package com.mes.web.controller.biz;

import java.util.List;
import java.util.HashMap;
import java.util.Map;

import com.mes.biz.domain.BizProductProcessPlan;
import com.mes.common.annotation.Log;
import com.mes.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.mes.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mes.common.enums.BusinessType;
import com.mes.common.utils.poi.ExcelUtil;
import com.mes.framework.cache.DictUtils;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.mes.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.mes.biz.domain.BizProductProcessDetail;
import com.mes.biz.service.BizProductProcessDetailService;

/**
 * 工序计划明细Controller
 * @author hwg
 * @email hwg
 * @date 2023-05-03
 */
@RestController
@RequestMapping("/biz/bizProductProcessDetail")
public class BizProductProcessDetailController extends BaseController {

    @Autowired
    private BizProductProcessDetailService bizProductProcessDetailService;

    /**
     * 查询工序计划明细列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductProcessDetail:list')")
    @GetMapping("/list")
    public R list(BizProductProcessDetail bizProductProcessDetail) {
        return R.data(bizProductProcessDetailService.listByPlan(bizProductProcessDetail));
    }

    /**
     * 获取工序计划明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductProcessDetail:query')")
    @GetMapping(value = "/{id}")
    public R<BizProductProcessDetail> detail(@PathVariable("id") String id) {
        return R.data(bizProductProcessDetailService.get(id));
    }

    /**
     * 新增工序计划明细
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductProcessDetail:add')")
    @Log(title = "工序计划明细", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody List<BizProductProcessDetail> bizProductProcessDetailList) {
        return R.status(bizProductProcessDetailService.addDetail(bizProductProcessDetailList));
    }

    /**
     * 修改工序计划明细
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductProcessDetail:edit')")
    @Log(title = "工序计划明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated BizProductProcessDetail bizProductProcessDetail) {
        return R.status(bizProductProcessDetailService.save(bizProductProcessDetail));
    }

    /**
     * 删除工序计划明细
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductProcessDetail:remove')")
    @Log(title = "工序计划明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(bizProductProcessDetailService.deleteBizProductProcessDetailByIds(ids));
    }


    /**
     * 导出工序计划明细列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizProductProcessDetail:export')")
    @Log(title = "工序计划明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(BizProductProcessDetail bizProductProcessDetail) {
        List<BizProductProcessDetail> list = bizProductProcessDetailService.findList(bizProductProcessDetail);
        ExcelUtil<BizProductProcessDetail> util = new ExcelUtil<BizProductProcessDetail>(BizProductProcessDetail.class);
        return util.exportExcel(list, "工序计划明细数据");
    }

    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

    @GetMapping(value = "/listBizProductProcessDetail/{processPlanId}")
    public R getBizProductProcessPlanByProductId(@PathVariable String processPlanId) {
        List<BizProductProcessDetail> bizProductProcessDetails = bizProductProcessDetailService.getBizProductProcessDetailByProcessPlanId(processPlanId);
        return R.data(bizProductProcessDetails);
    }
}
